package com.ruibang.glass.etl.handler.dcs;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.Dcsxz0908;
import com.ruibang.glass.etl.mapper.Dcsxz0908Mapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "dcs")
public class DCS0908XZBinlogEventHandler implements IBinlogEventHandler<Dcsxz0908> {

    @Autowired
    private Dcsxz0908Mapper dcs0908XZMapper;
    @Override
    public void onInsert(BinlogEvent<Dcsxz0908> event) {
        if(1 > dcs0908XZMapper.insert(event.getData())){
            String stringBuilder = event.getDatabase() + "-" +
                    event.getTable() + " insert record fail,data: " + event.getData();
            System.out.println(stringBuilder);
        }else
            System.out.println("dcs 0908xz 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<Dcsxz0908> event)  {

            if(1 > dcs0908XZMapper.updateById(event.getData())){
                String stringBuilder = event.getDatabase() + "-" +
                        event.getTable() + " update record fail,data: " + event.getData();
                System.out.println(stringBuilder);
            }else
                System.out.println("dcs 0908xz 更新数据成功");

    }

    @Override
    public void onDelete(BinlogEvent<Dcsxz0908> event) {

        if(1 > dcs0908XZMapper.deleteById(event.getData())){
            String stringBuilder = event.getDatabase() + "-" +
                    event.getTable() + " delete record fail,data: " + event.getData();
            System.out.println(stringBuilder);
        }else
            System.out.println("dcs 0908xz 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("dcsxz") && table.equals("0908xz");
    }
}
